package bancoArtigos.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import entities.User;
import entities.Comment;
import entities.Upvote;

public class ListaBDDAO extends BaseDAO {
    private Connection conn;
//------------------------------------------------------------------------------
    public ArrayList<Comment> listComments() {
        ArrayList<Comment> list = new ArrayList<>();
        try {
            conn = this.getConnection();
            PreparedStatement ps = conn.prepareStatement(
                                         "SELECT * FROM comments");
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                int id = rs.getInt("id");
                String text = rs.getString("text");
                Date timeStamp = rs.getDate("timeStamp");
                int posterId = rs.getInt("posterId");

                Comment c = new Comment();
                
                c.setCommentId(id);
                c.setText(text);
                c.setPosterId(posterId);
                c.setTimeStamp(timeStamp);
                list.add(c);
            }
            rs.close();
            ps.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
